home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / DefaultListSelectionModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  6.9 KB  |  376 lines

  1. package javax.swing;
  2.  
  3. import java.io.Serializable;
  4. import java.util.BitSet;
  5. import javax.swing.event.EventListenerList;
  6. import javax.swing.event.ListSelectionEvent;
  7. import javax.swing.event.ListSelectionListener;
  8.  
  9. public class DefaultListSelectionModel implements ListSelectionModel, Cloneable, Serializable {
  10.    private static final int MIN = -1;
  11.    private static final int MAX = Integer.MAX_VALUE;
  12.    private int selectionMode = 2;
  13.    private int minIndex = Integer.MAX_VALUE;
  14.    private int maxIndex = -1;
  15.    private int anchorIndex = -1;
  16.    private int leadIndex = -1;
  17.    private int firstAdjustedIndex = Integer.MAX_VALUE;
  18.    private int lastAdjustedIndex = -1;
  19.    private boolean isAdjusting = false;
  20.    private int firstChangedIndex = Integer.MAX_VALUE;
  21.    private int lastChangedIndex = -1;
  22.    private BitSet value = new BitSet(32);
  23.    protected EventListenerList listenerList = new EventListenerList();
  24.    protected boolean leadAnchorNotificationEnabled = true;
  25.    // $FF: synthetic field
  26.    static Class class$javax$swing$event$ListSelectionListener;
  27.  
  28.    public void addListSelectionListener(ListSelectionListener var1) {
  29.       this.listenerList.add(class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")), var1);
  30.    }
  31.  
  32.    public void addSelectionInterval(int var1, int var2) {
  33.       if (var1 != -1 && var2 != -1) {
  34.          if (this.getSelectionMode() != 2) {
  35.             this.setSelectionInterval(var1, var2);
  36.          } else {
  37.             this.updateLeadAnchorIndices(var1, var2);
  38.             int var3 = Integer.MAX_VALUE;
  39.             byte var4 = -1;
  40.             int var5 = Math.min(var1, var2);
  41.             int var6 = Math.max(var1, var2);
  42.             this.changeSelection(var3, var4, var5, var6);
  43.          }
  44.       }
  45.    }
  46.  
  47.    private void changeSelection(int var1, int var2, int var3, int var4) {
  48.       this.changeSelection(var1, var2, var3, var4, true);
  49.    }
  50.  
  51.    private void changeSelection(int var1, int var2, int var3, int var4, boolean var5) {
  52.       for(int var6 = Math.min(var3, var1); var6 <= Math.max(var4, var2); ++var6) {
  53.          boolean var7 = this.contains(var1, var2, var6);
  54.          boolean var8 = this.contains(var3, var4, var6);
  55.          if (var8 && var7) {
  56.             if (var5) {
  57.                var7 = false;
  58.             } else {
  59.                var8 = false;
  60.             }
  61.          }
  62.  
  63.          if (var8) {
  64.             this.set(var6);
  65.          }
  66.  
  67.          if (var7) {
  68.             this.clear(var6);
  69.          }
  70.       }
  71.  
  72.       this.fireValueChanged();
  73.    }
  74.  
  75.    // $FF: synthetic method
  76.    static Class class$(String var0) {
  77.       try {
  78.          return Class.forName(var0);
  79.       } catch (ClassNotFoundException var2) {
  80.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  81.       }
  82.    }
  83.  
  84.    private void clear(int var1) {
  85.       if (this.value.get(var1)) {
  86.          this.value.clear(var1);
  87.          this.markAsDirty(var1);
  88.          if (var1 == this.minIndex) {
  89.             ++this.minIndex;
  90.  
  91.             while(this.minIndex <= this.maxIndex && !this.value.get(this.minIndex)) {
  92.                ++this.minIndex;
  93.             }
  94.          }
  95.  
  96.          if (var1 == this.maxIndex) {
  97.             --this.maxIndex;
  98.  
  99.             while(this.minIndex <= this.maxIndex && !this.value.get(this.maxIndex)) {
  100.                --this.maxIndex;
  101.             }
  102.          }
  103.  
  104.          if (this.isSelectionEmpty()) {
  105.             this.minIndex = Integer.MAX_VALUE;
  106.             this.maxIndex = -1;
  107.          }
  108.  
  109.       }
  110.    }
  111.  
  112.    public void clearSelection() {
  113.       this.removeSelectionInterval(this.minIndex, this.maxIndex);
  114.    }
  115.  
  116.    public Object clone() throws CloneNotSupportedException {
  117.       DefaultListSelectionModel var1 = (DefaultListSelectionModel)super.clone();
  118.       var1.value = (BitSet)this.value.clone();
  119.       var1.listenerList = new EventListenerList();
  120.       return var1;
  121.    }
  122.  
  123.    private boolean contains(int var1, int var2, int var3) {
  124.       return var3 >= var1 && var3 <= var2;
  125.    }
  126.  
  127.    private void fireValueChanged() {
  128.       if (this.lastAdjustedIndex != -1) {
  129.          if (this.getValueIsAdjusting()) {
  130.             this.firstChangedIndex = Math.min(this.firstChangedIndex, this.firstAdjustedIndex);
  131.             this.lastChangedIndex = Math.max(this.lastChangedIndex, this.lastAdjustedIndex);
  132.          }
  133.  
  134.          int var1 = this.firstAdjustedIndex;
  135.          int var2 = this.lastAdjustedIndex;
  136.          this.firstAdjustedIndex = Integer.MAX_VALUE;
  137.          this.lastAdjustedIndex = -1;
  138.          this.fireValueChanged(var1, var2);
  139.       }
  140.    }
  141.  
  142.    protected void fireValueChanged(int var1, int var2) {
  143.       this.fireValueChanged(var1, var2, this.getValueIsAdjusting());
  144.    }
  145.  
  146.    protected void fireValueChanged(int var1, int var2, boolean var3) {
  147.       Object[] var4 = this.listenerList.getListenerList();
  148.       ListSelectionEvent var5 = null;
  149.  
  150.       for(int var6 = var4.length - 2; var6 >= 0; var6 -= 2) {
  151.          if (var4[var6] == (class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")))) {
  152.             if (var5 == null) {
  153.                var5 = new ListSelectionEvent(this, var1, var2, var3);
  154.             }
  155.  
  156.             ((ListSelectionListener)var4[var6 + 1]).valueChanged(var5);
  157.          }
  158.       }
  159.  
  160.    }
  161.  
  162.    protected void fireValueChanged(boolean var1) {
  163.       if (this.lastChangedIndex != -1) {
  164.          int var2 = this.firstChangedIndex;
  165.          int var3 = this.lastChangedIndex;
  166.          this.firstChangedIndex = Integer.MAX_VALUE;
  167.          this.lastChangedIndex = -1;
  168.          this.fireValueChanged(var2, var3, var1);
  169.       }
  170.    }
  171.  
  172.    public int getAnchorSelectionIndex() {
  173.       return this.anchorIndex;
  174.    }
  175.  
  176.    public int getLeadSelectionIndex() {
  177.       return this.leadIndex;
  178.    }
  179.  
  180.    public int getMaxSelectionIndex() {
  181.       return this.maxIndex;
  182.    }
  183.  
  184.    public int getMinSelectionIndex() {
  185.       return this.isSelectionEmpty() ? -1 : this.minIndex;
  186.    }
  187.  
  188.    public int getSelectionMode() {
  189.       return this.selectionMode;
  190.    }
  191.  
  192.    public boolean getValueIsAdjusting() {
  193.       return this.isAdjusting;
  194.    }
  195.  
  196.    public void insertIndexInterval(int var1, int var2, boolean var3) {
  197.       int var4 = var3 ? var1 : var1 + 1;
  198.       int var5 = var4 + var2 - 1;
  199.  
  200.       for(int var6 = this.maxIndex; var6 >= var4; --var6) {
  201.          this.setState(var6 + var2, this.value.get(var6));
  202.       }
  203.  
  204.       boolean var7 = this.value.get(var1);
  205.  
  206.       for(int var8 = var4; var8 <= var5; ++var8) {
  207.          this.setState(var8, var7);
  208.       }
  209.  
  210.    }
  211.  
  212.    public boolean isLeadAnchorNotificationEnabled() {
  213.       return this.leadAnchorNotificationEnabled;
  214.    }
  215.  
  216.    public boolean isSelectedIndex(int var1) {
  217.       return var1 >= this.minIndex && var1 <= this.maxIndex ? this.value.get(var1) : false;
  218.    }
  219.  
  220.    public boolean isSelectionEmpty() {
  221.       return this.minIndex > this.maxIndex;
  222.    }
  223.  
  224.    private void markAsDirty(int var1) {
  225.       this.firstAdjustedIndex = Math.min(this.firstAdjustedIndex, var1);
  226.       this.lastAdjustedIndex = Math.max(this.lastAdjustedIndex, var1);
  227.    }
  228.  
  229.    public void removeIndexInterval(int var1, int var2) {
  230.       int var3 = Math.min(var1, var2);
  231.       int var4 = Math.max(var1, var2);
  232.       int var5 = var4 - var3 + 1;
  233.  
  234.       for(int var6 = var3; var6 <= this.maxIndex; ++var6) {
  235.          this.setState(var6, this.value.get(var6 + var5));
  236.       }
  237.  
  238.    }
  239.  
  240.    public void removeListSelectionListener(ListSelectionListener var1) {
  241.       this.listenerList.remove(class$javax$swing$event$ListSelectionListener != null ? class$javax$swing$event$ListSelectionListener : (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")), var1);
  242.    }
  243.  
  244.    public void removeSelectionInterval(int var1, int var2) {
  245.       if (var1 != -1 && var2 != -1) {
  246.          this.updateLeadAnchorIndices(var1, var2);
  247.          int var3 = Math.min(var1, var2);
  248.          int var4 = Math.max(var1, var2);
  249.          int var5 = Integer.MAX_VALUE;
  250.          byte var6 = -1;
  251.          if (this.getSelectionMode() != 2 && var3 > this.minIndex && var4 < this.maxIndex) {
  252.             var4 = this.maxIndex;
  253.          }
  254.  
  255.          this.changeSelection(var3, var4, var5, var6);
  256.       }
  257.    }
  258.  
  259.    private void set(int var1) {
  260.       if (!this.value.get(var1)) {
  261.          this.value.set(var1);
  262.          this.markAsDirty(var1);
  263.          this.minIndex = Math.min(this.minIndex, var1);
  264.          this.maxIndex = Math.max(this.maxIndex, var1);
  265.       }
  266.    }
  267.  
  268.    public void setAnchorSelectionIndex(int var1) {
  269.       this.updateLeadAnchorIndices(var1, this.leadIndex);
  270.       this.anchorIndex = var1;
  271.       this.fireValueChanged();
  272.    }
  273.  
  274.    public void setLeadAnchorNotificationEnabled(boolean var1) {
  275.       this.leadAnchorNotificationEnabled = var1;
  276.    }
  277.  
  278.    public void setLeadSelectionIndex(int var1) {
  279.       int var2 = this.anchorIndex;
  280.       if (var2 != -1 && var1 != -1) {
  281.          if (this.leadIndex == -1) {
  282.             this.leadIndex = var1;
  283.          }
  284.  
  285.          if (this.getSelectionMode() == 0) {
  286.             var2 = var1;
  287.          }
  288.  
  289.          int var3 = Math.min(this.anchorIndex, this.leadIndex);
  290.          int var4 = Math.max(this.anchorIndex, this.leadIndex);
  291.          int var5 = Math.min(var2, var1);
  292.          int var6 = Math.max(var2, var1);
  293.          if (this.value.get(this.anchorIndex)) {
  294.             this.changeSelection(var3, var4, var5, var6);
  295.          } else {
  296.             this.changeSelection(var5, var6, var3, var4, false);
  297.          }
  298.  
  299.          this.anchorIndex = var2;
  300.          this.leadIndex = var1;
  301.       }
  302.    }
  303.  
  304.    public void setSelectionInterval(int var1, int var2) {
  305.       if (var1 != -1 && var2 != -1) {
  306.          if (this.getSelectionMode() == 0) {
  307.             var1 = var2;
  308.          }
  309.  
  310.          this.updateLeadAnchorIndices(var1, var2);
  311.          int var3 = this.minIndex;
  312.          int var4 = this.maxIndex;
  313.          int var5 = Math.min(var1, var2);
  314.          int var6 = Math.max(var1, var2);
  315.          this.changeSelection(var3, var4, var5, var6);
  316.       }
  317.    }
  318.  
  319.    public void setSelectionMode(int var1) {
  320.       switch (var1) {
  321.          case 0:
  322.          case 1:
  323.          case 2:
  324.             this.selectionMode = var1;
  325.             return;
  326.          default:
  327.             throw new IllegalArgumentException("invalid selectionMode");
  328.       }
  329.    }
  330.  
  331.    private void setState(int var1, boolean var2) {
  332.       if (var2) {
  333.          this.set(var1);
  334.       } else {
  335.          this.clear(var1);
  336.       }
  337.  
  338.    }
  339.  
  340.    public void setValueIsAdjusting(boolean var1) {
  341.       if (var1 != this.isAdjusting) {
  342.          this.isAdjusting = var1;
  343.          this.fireValueChanged(var1);
  344.       }
  345.  
  346.    }
  347.  
  348.    public String toString() {
  349.       String var1 = (this.getValueIsAdjusting() ? "~" : "=") + this.value.toString();
  350.       return this.getClass().getName() + " " + Integer.toString(this.hashCode()) + " " + var1;
  351.    }
  352.  
  353.    private void updateLeadAnchorIndices(int var1, int var2) {
  354.       if (this.leadAnchorNotificationEnabled) {
  355.          if (this.anchorIndex != var1) {
  356.             if (this.anchorIndex != -1) {
  357.                this.markAsDirty(this.anchorIndex);
  358.             }
  359.  
  360.             this.markAsDirty(var1);
  361.          }
  362.  
  363.          if (this.leadIndex != var2) {
  364.             if (this.leadIndex != -1) {
  365.                this.markAsDirty(this.leadIndex);
  366.             }
  367.  
  368.             this.markAsDirty(var2);
  369.          }
  370.       }
  371.  
  372.       this.anchorIndex = var1;
  373.       this.leadIndex = var2;
  374.    }
  375. }
  376.